package com.myz.rabbitmq.study6;

import com.myz.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class ReceiveLogsDirect02 {
    // exchange name
    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        // get channel
        Channel channel = RabbitMqUtils.getChannel();
        // get temp queue name
//        String queueName = channel.queueDeclare().getQueue();
        // declare a exchange (exchangName,ExchangeType)
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // declare a queue (queueName
        channel.queueDeclare("disk",false,false,false,null);
        // binding exchange and queue,(queuename,exchangeName,routing key)
        channel.queueBind("disk",EXCHANGE_NAME,"error");
        System.out.println("waiting receive message");
        DeliverCallback deliverCallback = (var1,var2) -> {
            System.out.println("ReceiveLogsDirect02接收消息:"+new String(var2.getBody(),"UTF-8"));
        };
        channel.basicConsume("disk",true,deliverCallback, (CancelCallback) null);
    }
}
